
package com.abl.lib.db.strengthen;


import com.baomidou.mybatisplus.core.conditions.SharedString;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

/**
 * 强化Wrapper
 */
public class Wrapper<T> extends UpdateWrapper<T> {

    /**
     * 查询字段
     */
    private final SharedString sqlSelect = new SharedString();

    public Wrapper<T> select(String... columns) {
        if (ArrayUtils.isNotEmpty(columns)) {
            this.sqlSelect.setStringValue(String.join(StringPool.COMMA, columns));
        }
        return this;
    }

    public String getSqlSelect() {
        return sqlSelect.getStringValue();
    }

    public Wrapper<T> findInSet(boolean condition, String column, Object val) {
        this.apply(condition, "FIND_IN_SET({0},`" + column + "`)", val);
        return this;
    }

    public Wrapper<T> findInSet(String column, Object val) {
        return findInSet(true, column, val);
    }

}
